package com.liukai.todo_android.ui.adapter;

import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.liukai.todo_android.R;
import com.liukai.todo_android.entity.DetailVo;
import com.liukai.todo_android.entity.ItemVo;

import org.jetbrains.annotations.NotNull;

import java.util.List;

/**
 * @author ：liukai
 * @date ：Created in 2021/8/25 5:03 下午
 * @description：详情列表的适配器
 * @modified By：
 * @version: $
 */
public class DetailRecyclerViewAdapter extends RecyclerView.Adapter<DetailRecyclerViewAdapter.DetailHolder> {


    List<DetailVo> detailVoList;

    public DetailRecyclerViewAdapter(ItemVo itemVo) {
        this.detailVoList = DetailVo.buildDetailList(itemVo);
    }

    @NonNull
    @NotNull
    @Override
    public DetailHolder onCreateViewHolder(@NonNull @NotNull ViewGroup parent, int viewType) {
        View view = View.inflate(parent.getContext(), R.layout.item_detail, null);
        return new DetailHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull @NotNull DetailRecyclerViewAdapter.DetailHolder holder, int position) {
        DetailVo detailVo = detailVoList.get(position);
        holder.tvTitle.setText(detailVo.getTitle());
        holder.tvContent.setText(detailVo.getContent());
    }

    @Override
    public int getItemCount() {
        return detailVoList.size();
    }

    class DetailHolder extends RecyclerView.ViewHolder {

        public TextView tvTitle;
        public TextView tvContent;

        public DetailHolder(@NonNull @NotNull View itemView) {
            super(itemView);
            tvTitle = itemView.findViewById(R.id.tv_title);
            tvContent = itemView.findViewById(R.id.tv_content);
        }
    }

}
